#include <kernel.h>

extern dde_kit_addr_t *inv_map;

struct dde_kit_slab
{
	 int size;
	 void *user_data;
};

void
LD_SYM(dde_kit_slab_set_data)(struct dde_kit_slab * slab, void *data)
{
	 slab->user_data = data;
}

void *
LD_SYM(dde_kit_slab_get_data)(struct dde_kit_slab * slab)
{
	 return slab->user_data;
}

void *
LD_SYM(dde_kit_slab_alloc)(struct dde_kit_slab * slab)
{
	 return ekf_alloc(slab->size);
}

void
LD_SYM(dde_kit_slab_free)(struct dde_kit_slab * slab, void *objp)
{
	 if (objp) ekf_free(objp);
}

void
LD_SYM(dde_kit_slab_destroy)(struct dde_kit_slab * slab)
{
	 if (slab) ekf_free(slab);
}

struct dde_kit_slab *
LD_SYM(dde_kit_slab_init)(unsigned size)
{
	 struct dde_kit_slab *result = (struct dde_kit_slab *)
		  ekf_alloc(sizeof(struct dde_kit_slab));
	 result->user_data = 0;
	 result->size = size;
	 return result;
}

void *
LD_SYM(dde_kit_large_malloc)(dde_kit_size_t size)
{
	 void *r = ekf_palloc(size, 0);
	 return r;
}


void
LD_SYM(dde_kit_large_free)(void *p)
{
	 if (p) ekf_pfree(p);
}


void *
LD_SYM(dde_kit_simple_malloc)(dde_kit_size_t size)
{
	 return ekf_alloc(size);
}

void
LD_SYM(dde_kit_simple_free)(void *p)
{
	 if (p) ekf_free(p);
}

#if DK_EXPORT_SYM

void
dde_kit_memory_symbol(void)
{
	 elf_mod_export_symbol("dde_kit_slab_alloc", &dde_kit_slab_alloc, 1);
	 elf_mod_export_symbol("dde_kit_slab_free", &dde_kit_slab_free, 1);
	 elf_mod_export_symbol("dde_kit_slab_get_data", &dde_kit_slab_get_data, 1);
	 elf_mod_export_symbol("dde_kit_slab_set_data", &dde_kit_slab_set_data, 1);
	 elf_mod_export_symbol("dde_kit_slab_init", &dde_kit_slab_init, 1);
	 elf_mod_export_symbol("dde_kit_slab_destroy", &dde_kit_slab_destroy, 1);
	 elf_mod_export_symbol("dde_kit_large_malloc", &dde_kit_large_malloc, 1);
	 elf_mod_export_symbol("dde_kit_large_free", &dde_kit_large_free, 1);
	 elf_mod_export_symbol("dde_kit_simple_malloc", &dde_kit_simple_malloc, 1);
	 elf_mod_export_symbol("dde_kit_simple_free", &dde_kit_simple_free, 1);
}

#endif
